package cn.edu.ujn.zzylab4.service;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import cn.edu.ujn.zzylab4.dao.User;

/**
 * Session Bean implementation class UserFacade
 */
@Stateless
@LocalBean
public class UserFacade implements UserFacadeRemote {
@PersistenceContext
private EntityManager entityManager;
    /**
     * Default constructor. 
     */
    public UserFacade() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public User checkLogin(User user) {
		Query query = entityManager.createQuery("from User where username=:username and password=:password");
		query.setParameter("username", user.getUsername());
		query.setParameter("password", user.getPassword());
		List<User> list = query.getResultList();
		if(list.size()>0)
			return list.get(0);
		else
			return null;

	}

}
